home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / rTutors / part3 / rTutor.rez < prev    next >
Encoding:
Text File  |  1990-06-19  |  12.2 KB  |  472 lines  |  [TEXT/pdos]

  1. /* File: Rtutor.Rez */
  2. /* Rez source file for C version of resource tutorial */
  3. /* Part 1:  starting up & shutting down the tools using a resource */
  4. /* Part 2:  do Part 1 and insert a menubar with menus */
  5. /* Part 2.5:  do part 2 and add an event loop so app stays up */
  6. /* Part 3:  do part 2.5 and add a window (w/ controls) from a resource */
  7.  
  8. /* this gives use access to the "standard" pre-defined resource types */
  9. #include "Types.rez"
  10.  
  11. /*---------------------- Startup Record ---------------------------*/
  12. resource rToolStartup (1)
  13. {
  14.  $C080,       /* set master SCB to mode640 + fFastPortAware + fUseShadowing */
  15.  {
  16.   3,$0300,      /* misc tools */
  17.   4,$0302,      /* quickdraw */
  18.   5,$0302,      /* desk manager */
  19.   6,$0300,      /* eventMgr */
  20. /*  7,$0300,      /* scheduler */ /* not used by apps or DA's */
  21. /*  8,$0301,      /* sound tools */ /* not used by this app */
  22. /*  9,$0300,      /* ADB tools */ /* not used by this app */
  23. /*  10,$0300,      /* SANE */ /* started already by pStart.obj */
  24.   11,$0300,      /* int math */
  25.   14,$0301,      /* Window Manager */
  26.   15,$0301,      /* Menu Manager */
  27.   16,$0300,      /* Control Manager */
  28.   18,$0301,      /* QD Aux */
  29.   19,$0300,      /* print manager */
  30.   20,$0301,      /* LineEdit tool set */
  31.   21,$0302,      /* Dialog Manager */
  32.   22,$0300,      /* Scrap manager */
  33.   23,$0301,      /* standard file */
  34.   27,$0301,      /* Font manager */
  35.   28,$0301,      /* list manager */
  36.   34,$0101,      /* text edit */
  37. /*  29,$0100,      /* ACE */ /* not used by this app */
  38. /*  32,$0100,      /* Midi Tools */ /* not used by this app */
  39. /*  25,$0100,      /* NoteSynth */ /* not used by this app */
  40. /*  26,$0100      /* Note Seq */ /* not used by this app */
  41.  }
  42. };
  43.  
  44.  
  45. /*---------------------- Menus & Menu Bars ---------------------------*/
  46.     /* define the resource id of the menu bar itself */
  47. #define    kMenuBarID1       1
  48.  
  49.     /* define all the menu id's */
  50. #define    kAppleMID   1000
  51. #define    kFileMID    2000
  52. #define    kEditMID    3000
  53.  
  54.     /* now, define the menu item id's */
  55. #define    kAboutBoxIID    1001 /* the "About..." box */
  56.     
  57. #define    kNewItem        2001 /* the "New" item */
  58. #define    kOpenItem       2002 /* the "Open..." item */
  59. #define    kCloseItem       255 /* the "Close" item */
  60. #define    kSaveItem       2004 /* the "Save" item */
  61. #define    kSaveAsItem     2005 /* the "Save As..." item */
  62. #define    kQuitItem       2009 /* the "Quit" item */
  63.       
  64. #define    kUndoItem        250 /* the "Undo" item */
  65. #define    kCutItem         251 /* the "Cut" item */
  66. #define    kCopyItem        252 /* the "Copy" item */
  67. #define    kPasteItem       253 /* the "Paste" item */
  68. #define    kClearItem       254 /* the "Clear" item */
  69. #define    kSelectItem     3001 /* the "Select All" item */
  70. #define    kShowClipItem   3002 /* the "Show Clipboard" item */
  71.       
  72.     /* now, define the menu bar */
  73. resource rMenuBar (kMenuBarID1)
  74. {
  75.     {
  76.         kAppleMID,
  77.         kFileMID,
  78.         kEditMID,
  79.     };
  80. };
  81.  
  82.  
  83. /* lay out the Apple menu */
  84. /* this takes several steps: */
  85. /* 1)  define the menu itself in a resource of type "rMenu" */
  86. /* 2)  define the rPString that will be used for the name of the menu */
  87. /* 3)  define the first item in the menu in a resource of type "rMenuItem" */
  88. /* 4)  define the rPString that will be used for the name of the first item */
  89. /* 5)  repeat steps 3 and 4 for all remaining items in that menu */
  90. /* 6)  repeat steps 1 through 5 for all remaining menus */
  91.     
  92. resource rMenu (kAppleMID, nocrossbank)
  93. {
  94.     kAppleMID,    /* ID of the menu this item belongs to */
  95.     0xA008, /* flags => menu title is a resource, items are resources, menu */
  96.             /* is enabled, XOR highlighting, std menu, caching ok */
  97.     kAppleMID,    /* ref to menu's title */
  98.     { kAboutBoxIID }; /* array of items in this menu (only 1 to start with) */
  99. };
  100.  
  101. resource rPString (kAppleMID, nocrossbank)
  102. {
  103.     "@"                    /* this string is the title of the "Apple" menu */
  104. };
  105.  
  106. /* see IIGS Toolbox Reference, Volume 3, menu item template */
  107. resource rMenuItem (kAboutBoxIID, nocrossbank)
  108. {
  109.     kAboutBoxIID, /* item's ID */
  110.     "",           /* no keyboard equivalent */
  111.     "",           /* no keyboard equivalent (allowed 2, this is the 2nd) */
  112.     0,            /* this item does not have a check mark by it */
  113.     0x8040,       /* title is in a resource, enabled (bit 7=0), */
  114.                   /* dividing line below (bit 6=1)  */
  115.     kAboutBoxIID  /* ref of the item's title */
  116. };
  117.  
  118. resource rPString (kAboutBoxIID, nocrossbank)
  119. {
  120.     "About rTutor" /* used as the title for the "About..." item */
  121. };
  122.  
  123.  
  124.     /* lay out the File menu */
  125.     
  126. resource rMenu (kFileMID, nocrossbank)
  127. {
  128.     kFileMID,  /* ID of the menu this item belongs to */
  129.     0xA008,    /* flags => menu title is a resource, items are resources, */
  130.                /* menu is enabled, don't use XOR highlighting, std menu,  */
  131.                /* caching ok */
  132.     kFileMID,  /* ref to menu's title */
  133.     {          /* array of items in this menu */
  134.         kNewItem,
  135.         kOpenItem,
  136.         kCloseItem,
  137.         kSaveItem,
  138.         kSaveAsItem,
  139.         kQuitItem
  140.     };
  141. };
  142.  
  143. resource rPString (kFileMID, nocrossbank)
  144. {
  145.     " File "   /* this string is the title of the "File" menu */
  146. };
  147.  
  148. resource rMenuItem (kNewItem, nocrossbank)
  149. {
  150.     kNewItem,  /* item's ID */
  151.     "N",       /* keyboard equivalent = "N" */
  152.     "n",       /* or = "n" (either key will work) */
  153.     0,         /* this item does not have a check mark by it */
  154.     0x8000,    /* title is in a resource, enabled (bit 7 = 0)  */
  155.     kNewItem   /* ref of the item's title */
  156. };
  157.  
  158. resource rPString (kNewItem, nocrossbank)
  159. {
  160.     "New"      /* this string is used as the title for the "New" item */
  161. };
  162.  
  163. resource rMenuItem (kOpenItem, nocrossbank)
  164. {
  165.     kOpenItem,
  166.     "O",       /* that's an "OH" on this line, not a "zero" */
  167.     "o",       /* that's an "OH" on this line, not a "zero" */
  168.     0,         /* this one's a "zero" */
  169.     0x8040,    /* the "4" means put a dividing line under this item */
  170.     kOpenItem
  171. };
  172.  
  173. resource rPString (kOpenItem, nocrossbank)
  174. {
  175.     "Open..."
  176. };
  177.  
  178. resource rMenuItem (kCloseItem, nocrossbank)
  179. {
  180.     kCloseItem,
  181.     "W",
  182.     "w",
  183.     0,
  184.     0x8000,
  185.     kCloseItem
  186. };
  187.  
  188. resource rPString (kCloseItem, nocrossbank)
  189. {
  190.     "Close"
  191. };
  192.  
  193. resource rMenuItem (kSaveItem, nocrossbank)
  194. {
  195.     kSaveItem,
  196.     "S",
  197.     "s",
  198.     0,
  199.     0x8000,
  200.     kSaveItem
  201. };
  202.  
  203. resource rPString (kSaveItem, nocrossbank)
  204. {
  205.     "Save"
  206. };
  207.  
  208. resource rMenuItem (kSaveAsItem, nocrossbank)
  209. {
  210.     kSaveAsItem,
  211.     "",        /* no key equivalents for this item */
  212.     "",
  213.     0,
  214.     0x8000,
  215.     kSaveAsItem    
  216. };
  217.  
  218. resource rPString (kSaveAsItem, nocrossbank)
  219. {
  220.     "Save As..."
  221. };
  222.  
  223. resource rMenuItem (kQuitItem, nocrossbank)
  224. {
  225.     kQuitItem,
  226.     "Q",
  227.     "q",
  228.     0,
  229.     0x8000,
  230.     kQuitItem    
  231. };
  232.  
  233. resource rPString (kQuitItem, nocrossbank)
  234. {
  235.     "Quit"
  236. };
  237.  
  238.  
  239.     /* lay out the Edit menu */
  240.     
  241. resource rMenu (kEditMID, nocrossbank)
  242. {
  243.     kEditMID,    /* ID of the menu this item belongs to */
  244.     0xA008,
  245.     kEditMID,    /* ref to menu's title */
  246.     {            /* array of items in this menu */
  247.         kUndoItem,
  248.         kCutItem,
  249.         kCopyItem,
  250.         kPasteItem,
  251.         kClearItem,
  252.         kSelectItem,
  253.         kShowClipItem
  254.     };
  255. };
  256.  
  257. resource rPString (kEditMID, nocrossbank)
  258. {
  259.     " Edit "   /* this string is the title of the "Edit" menu */
  260. };
  261.  
  262. resource rMenuItem (kUndoItem, nocrossbank)
  263. {
  264.     kUndoItem,
  265.     "Z",
  266.     "z",
  267.     0,
  268.     0x8040,
  269.     kUndoItem
  270. };
  271.  
  272. resource rPString (kUndoItem, nocrossbank)
  273. {
  274.     "Undo"
  275. };
  276.  
  277. resource rMenuItem (kCutItem, nocrossbank)
  278. {
  279.     kCutItem,
  280.     "X",
  281.     "x",
  282.     0,
  283.     0x8000,
  284.     kCutItem
  285. };
  286.  
  287. resource rPString (kCutItem, nocrossbank)
  288. {
  289.     "Cut"
  290. };
  291.  
  292. resource rMenuItem (kCopyItem, nocrossbank)
  293. {
  294.     kCopyItem,
  295.     "C",
  296.     "c",
  297.     0,
  298.     0x8000,
  299.     kCopyItem
  300. };
  301.  
  302. resource rPString (kCopyItem, nocrossbank)
  303. {
  304.     "Copy"
  305. };
  306.  
  307. resource rMenuItem (kPasteItem, nocrossbank)
  308. {
  309.     kPasteItem,
  310.     "V",
  311.     "v",
  312.     0,
  313.     0x8000,
  314.     kPasteItem
  315. };
  316.  
  317. resource rPString (kPasteItem, nocrossbank)
  318. {
  319.     "Paste"
  320. };
  321.  
  322. resource rMenuItem (kClearItem, nocrossbank)
  323. {
  324.     kClearItem,
  325.     "",
  326.     "",
  327.     0,
  328.     0x8000,
  329.     kClearItem
  330. };
  331.  
  332. resource rPString (kClearItem, nocrossbank)
  333. {
  334.     "Clear"
  335. };
  336.  
  337. resource rMenuItem (kSelectItem, nocrossbank)
  338. {
  339.     kSelectItem,
  340.     "A",
  341.     "a",
  342.     0,
  343.     0x8040,  /* the "4" means this one has a divider under it */
  344.     kSelectItem
  345. };
  346.  
  347. resource rPString (kSelectItem, nocrossbank)
  348. {
  349.     "Select All"
  350. };
  351.  
  352. resource rMenuItem (kShowClipItem, nocrossbank)
  353. {
  354.     kShowClipItem,
  355.     "",
  356.     "",
  357.     0,
  358.     0x8000,
  359.     kShowClipItem
  360. };
  361.  
  362. resource rPString (kShowClipItem, nocrossbank)
  363. {
  364.     "Show Clipboard"
  365. };
  366.  
  367.  
  368. /*---------------------- Windows and their contents --------------------------*/
  369.     /* define the resource ID's for all windows used by this app */
  370. #define myWindowID    2362  /* window's resource ID = 2362 */
  371.  
  372. /* First, we lay out the window itself */
  373. resource rWindParam1 (myWindowID) 
  374. {
  375.  fTitle+fMove+fVis, /* has a title, can be moved, and it is visible */
  376.  myWindowID,         /* resource ID of the title */
  377.  0,                 /* no ref Con needed */
  378.  {0,0,0,0},         /* no zoom box, so we don't care about the zoom rect */
  379.  0,                 /* use std color table for now */
  380.  {0,0},             /* upper left corner of vis rgn = upper left of document */
  381.  {0,0},             /* we don't really have a "document" for this window, so */
  382.                     /* set the data size to zero */
  383.  {0,0},             /* maximum height and width */
  384.  {0,0},             /* don't scroll vertically or horizontally */
  385.  {0,0},             /* no "document", so page size is zero also */
  386.  0,                 /* passed to info bar draw routine - not used here */
  387.  0,                 /* height of info bar - not used here */
  388.  {46,100,176,540},  /* this rect defines the boundaries of the window */
  389.  infront,           /* window comes up in front of other windows */
  390.  0,                 /* set to NIL to avoid bug in NewWindow2 */
  391.  refIsResource*0x0100+resourceToResource /* title string and */
  392.                                          /* control list are resources */
  393. };
  394.  
  395. /* define the title string used by our window */
  396. resource rPstring (myWindowID)
  397. {
  398.     " This came from a resource "
  399. };
  400.  
  401.  
  402. /* define the list of controls that are in the default window */
  403. /* we're taking it easy for now and are putting in only: */
  404. /* a simple round button and a text edit field */
  405. /* so, we need to define the constants used by those controls */
  406.  
  407. #define myRoundButton    $0001
  408. #define myTEField       $0002
  409.  
  410. resource rControlList (myWindowID) 
  411. {
  412.  {
  413.  myRoundButton,
  414.  myTEField,
  415.  };
  416.   /* last item in a control list HAS to be NIL, but the template for a */
  417.   /* rControlList takes care of sticking the NIL in there for us!  */
  418. };
  419.  
  420. /* define the simple round button */
  421. resource rControlTemplate (myRoundButton) 
  422. {
  423.  myRoundButton, /* ID of this control */
  424.  {8,152, 22, 290}, /* boundary rect for button  */
  425.  SimpleButtonControl    /* type of control */
  426.  {
  427.   { 
  428.    0, /* button is visible and has simple rounded corners */
  429.    0x1002, /* bit 12 MUST be set!!! and title is in a resource */
  430.    0, /* ignore the ref con */
  431.    myRoundButton /* resource ID of title string */
  432.   }
  433.  };
  434. };
  435.  
  436. /* define the title string used by the simple button */
  437. resource rpString (myRoundButton) 
  438. {
  439.  "Rent this space"
  440. };
  441.  
  442. /* define the text edit field */
  443. resource rControlTemplate (myTEField) 
  444. {
  445.   myTEField, /* ID of the text edit control */
  446.  {30,10,120,430}, /* bounding rectangle for the text edit field */
  447.  EditTextControl    /* type of control */
  448.  {
  449.   { 
  450.     0x0000, /* field is visible ("flag" field") */
  451.     0x7400, /* see Toolbox Ref, volume 3 for details */
  452.     0, /* ignore the ref con */
  453.     0x42A80000, /* text flags - see Toolbox Ref, volume 3 */
  454.     {$FFFF,$FFFF,$FFFF,$FFFF}, /* use std values for indent rect */
  455.     $FFFFFFFF, /* allow vertical scroll bar */
  456.     0, /* use default vertical scroll amount */
  457.     0, /* horzBar - MUST be NIL */
  458.     0, /* horzAmount - MUST be zero */
  459.     0, /* use default style and ruler info */
  460.     dataIsPString+RefIsResource*8, /* default text is in a rPstring resource */
  461.     myTEField, /* resource ID of default text */
  462.     0 /* text length - set by toolbox when text resource is read in */
  463.   }
  464.  };
  465. }; 
  466.  
  467. /* define the text that will show up when the text edit field is created */
  468. resource rPString (myTEField) 
  469. {
  470. "Try selecting this text, then pick COPY, CUT, and/or PASTE from the EDIT menu."
  471. };
  472.